package com.service.impl;

import com.baomidou.mybatisplus.extension.service.IService;
import com.entity.Employee;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mapper.EmployeeMapper;
import com.service.EmployeeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.utils.AesUtils;
import com.utils.PageObject;
import com.vo.EmployeeVO;
import com.vo.StorageReportVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 *  员工服务实现类
 */
@Service
public class EmployeeServiceImpl implements EmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    //用户管理：分页和下拉框查询
    @Override
    public PageObject<EmployeeVO> list(PageObject pageObject, Employee employee) {
        //开始分页
        PageHelper.startPage(pageObject.getCurrent(),pageObject.getSize());
        //查询数据
        List<EmployeeVO> list = employeeMapper.list(employee);
        //PageHelper包装数据
        PageInfo<EmployeeVO> pageInfo = new PageInfo<>(list);
        //将数据封装进PageResult
        PageObject<EmployeeVO> EmployeeVoPageResult
                = new PageObject<>(pageInfo.getPageNum(), pageInfo.getPageSize(), pageInfo.getTotal(), pageInfo.getList());
        return EmployeeVoPageResult;
    }

    //用户管理：设置状态
    @Override
    public boolean setStatus(Integer status, Integer id) {
        int setStatus = this.employeeMapper.setStatus(status, id);
        if(setStatus == 1) return true;
        return false;
    }

    //用户管理：重置密码
    @Override
    public boolean resetPassword(Integer id) {
        String password = AesUtils.encryptStr("123456", AesUtils.SECRETKEY);
        int resetPassword = this.employeeMapper.resetPassword(password, id);
        if(resetPassword == 1) return true;
        return false;
    }

    //用户管理：添加功能保存
    @Override
    public boolean save(Employee employee) {
        return employeeMapper.save(employee);
    }

    //用户管理：编辑员工-Id查询
    @Override
    public Employee getById(Integer id) {
        return employeeMapper.seletcById(id);
    }

    //用户管理：编辑员工
    @Override
    public boolean updateById(Employee employee) {
        return employeeMapper.updateById(employee);
    }

    //用户管理：删除员工
    @Override
    public boolean removeById(Integer id) {
        return employeeMapper.deleteById(id);
    }

    //部门管理：查询所有员工
    @Override
    public List<Employee> list() {
        return employeeMapper.listAllEmployee();
    }

    //登录：查询手机号
    @Override
    public Employee selectByPhone(String phone) {
        return employeeMapper.selectByPhone(phone);
    }

    //用户权限：查询部门所有员工
    @Override
    public List<Employee> list(Integer departmentId) {
        return employeeMapper.selectByDepartmentId(departmentId);
    }


}
